﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.Library;
using System.IO;
using AutoGear.BLL;
using Entity;
using eShop.Model;
using eShop.Business;

public partial class admin_manufacturer_add : SiteAdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Create_Click(object sender, EventArgs e)
    {
        try
        {
            if (IsValid)
            {
                string name = tbxBrandName.Text.Trim();
                string tempImageFolder = UploadTemporaryFiles();
                string tmpPartnerBanner = UploadTemporaryBannerFiles();
                Manufacturer productBrand = ManufacturerManager.Create(name, string.Empty, tempImageFolder, cbxIsActive.Checked, false, string.Empty, tmpPartnerBanner);

                uccResponseMessage.SetSuccessMessage("Partner Created Successfully");
                uccResponseMessage.Visible = true;
            }
        }
        catch (Exception ex)
        {
            uccResponseMessage.SetFailMessage("Failed to create partner");
            uccResponseMessage.Visible = true;
        }
    }


    protected string UploadTemporaryFiles()
    {
        string tempImageFolder = string.Empty;
        if (fluPartnerImage.HasFile)
        {
            tempImageFolder = SiteUtility.TempFolder + fluPartnerImage.FileName;

            if (File.Exists(MapPath(tempImageFolder)))
                FileAccessUtility.DeleteFile(tempImageFolder);

            string contentType = fluPartnerImage.PostedFile.ContentType.ToLower();
            if (contentType == "image/jpg" || contentType == "image/gif" || contentType == "image/png"
                || contentType == "image/jpeg" || contentType == "image/bmp" || contentType == "image/pjpeg"
                || contentType == "image/x-png")
            {
                fluPartnerImage.SaveAs(MapPath(tempImageFolder));
            }

        }
        return tempImageFolder;
    }

    protected string UploadTemporaryBannerFiles()
    {
        string tempImageFolder = string.Empty;
        if (fluPartnerBannerImage.HasFile)
        {
            tempImageFolder = ProductFileAccessUtility._brandBannerPath + fluPartnerBannerImage.FileName;

            if (File.Exists(MapPath(tempImageFolder)))
                FileAccessUtility.DeleteFile(tempImageFolder);

            string contentType = fluPartnerBannerImage.PostedFile.ContentType.ToLower();
            if (contentType == "image/jpg" || contentType == "image/gif" || contentType == "image/png"
                || contentType == "image/jpeg" || contentType == "image/bmp" || contentType == "image/pjpeg"
                || contentType == "image/x-png")
            {
                fluPartnerBannerImage.SaveAs(MapPath(tempImageFolder));
            }

        }
        return fluPartnerBannerImage.FileName;
    }
}